﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Chinook.Core.DomainModel
{
    public class Person : EntityBase
    {
        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }
        public virtual string Title { get; set; }
        public virtual DateTime BirthDate { get; set; }
        public virtual string StreetAddressLine1 { get; set; }
        public virtual string StreetAddressLine2 { get; set; }
        public virtual string City { get; set; }
        public virtual string State { get; set; }
        public virtual string Country { get; set; }
        public virtual string PostalCode { get; set; }
        public virtual string Phone { get; set; }
        public virtual string Fax { get; set; }
        public virtual string Email { get; set; }
        private string _address = string.Empty;
        public virtual string Name { get { return string.IsNullOrEmpty(LastName) ? FirstName : LastName + " " + FirstName; } }
        public virtual string Address
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                //Street line
                if (!string.IsNullOrEmpty(StreetAddressLine1)) { sb.Append(StreetAddressLine1).Append(Environment.NewLine); }
                if (!string.IsNullOrEmpty(StreetAddressLine2)) { sb.Append(StreetAddressLine1).Append(Environment.NewLine); }
                //City line
                Boolean CityLine = false;
                if (!string.IsNullOrEmpty(City)) { sb.Append(City); CityLine = true; }
                if (!string.IsNullOrEmpty(State)) { sb.Append(", ").Append(State); CityLine = true; }
                if (!string.IsNullOrEmpty(PostalCode)) { sb.Append(" ").Append(PostalCode); CityLine = true; }
                if (CityLine) { sb.Append(Environment.NewLine); }
                //Country
                if (!string.IsNullOrEmpty(Country)) { sb.Append(Country); }
                return sb.ToString();
            }
            set{_address=String.IsNullOrEmpty(value) ? String.Empty : value;}
        }
        public virtual string Contact { get { return Name + Environment.NewLine + Address; } }

        #region "Business Rules"
        #endregion

        protected override void CheckForBrokenRules()
        {
            throw new NotImplementedException();
        }
    }
}
